package demo2;

public class LeetCode209 {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length, min = n + 1;
        int sum = 0;
        for (int left = 0, right = 0; right < n; right++) {
            sum += nums[right];
            while (sum >= target)  {
                min = Math.min(min, right - left + 1);
                sum -= nums[left++];
            }
        }
        return min == n + 1 ? 0 : min;
    }
}
